/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cw.entity;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author VinhTC
 */
@Entity
@Table(name = "tblQuestion")
@NamedQueries({
    @NamedQuery(name = "Question.findAll", query = "SELECT q FROM Question q"),
    @NamedQuery(name = "Question.findByQuestionId", query = "SELECT q FROM Question q WHERE q.questionId = :questionId"),
    @NamedQuery(name = "Question.findByPuzzleId", query = "SELECT q FROM Question q WHERE q.puzzle.puzzleId = :puzzleId"),
    @NamedQuery(name = "Question.findByQuestion", query = "SELECT q FROM Question q WHERE q.question like :question"),
    @NamedQuery(name = "Question.findByAnswer", query = "SELECT q FROM Question q WHERE q.answer = :answer"),
    @NamedQuery(name = "Question.findByPositionY", query = "SELECT q FROM Question q WHERE q.positionY = :positionY"),
    @NamedQuery(name = "Question.findByPositionX", query = "SELECT q FROM Question q WHERE q.positionX = :positionX"),
    @NamedQuery(name = "Question.findByDirection", query = "SELECT q FROM Question q WHERE q.direction = :direction"),
    @NamedQuery(name = "Question.findByStatus", query = "SELECT q FROM Question q WHERE q.status = :status")})
public class Question implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "QuestionId")
    private Integer questionId;
    @Basic(optional = false)
    @Column(name = "Question")
    private String question;
    @Basic(optional = false)
    @Column(name = "Answer")
    private String answer;
    @Basic(optional = false)
    @Column(name = "PositionY")
    private int positionY;
    @Basic(optional = false)
    @Column(name = "PositionX")
    private int positionX;
    @Basic(optional = false)
    @Column(name = "Direction")
    private boolean direction;
    @Basic(optional = false)
    @Column(name = "Status")
    private boolean status;
    @JoinColumn(name = "PuzzleId", referencedColumnName = "PuzzleId")
    @ManyToOne(optional = false)
    private Puzzle puzzle;

    public Question() {
    }

    public Question(Integer questionId) {
        this.questionId = questionId;
    }

    public Question(Integer questionId, String question, String answer, int positionY, int positionX, boolean direction, boolean status) {
        this.questionId = questionId;
        this.question = question;
        this.answer = answer;
        this.positionY = positionY;
        this.positionX = positionX;
        this.direction = direction;
        this.status = status;
    }

    public Integer getQuestionId() {
        return questionId;
    }

    public void setQuestionId(Integer questionId) {
        Integer oldQuestionId = this.questionId;
        this.questionId = questionId;
        changeSupport.firePropertyChange("questionId", oldQuestionId, questionId);
    }

    public String getQuestion() {
        return question;
    }

    public void setQuestion(String question) {
        String oldQuestion = this.question;
        this.question = question;
        changeSupport.firePropertyChange("question", oldQuestion, question);
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        String oldAnswer = this.answer;
        this.answer = answer;
        changeSupport.firePropertyChange("answer", oldAnswer, answer);
    }

    public int getPositionY() {
        return positionY;
    }

    public void setPositionY(int positionY) {
        int oldPositionY = this.positionY;
        this.positionY = positionY;
        changeSupport.firePropertyChange("positionY", oldPositionY, positionY);
    }

    public int getPositionX() {
        return positionX;
    }

    public void setPositionX(int positionX) {
        int oldPositionX = this.positionX;
        this.positionX = positionX;
        changeSupport.firePropertyChange("positionX", oldPositionX, positionX);
    }

    public boolean getDirection() {
        return direction;
    }

    public void setDirection(boolean direction) {
        boolean oldDirection = this.direction;
        this.direction = direction;
        changeSupport.firePropertyChange("direction", oldDirection, direction);
    }

    public boolean getStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        boolean oldStatus = this.status;
        this.status = status;
        changeSupport.firePropertyChange("status", oldStatus, status);
    }

    public Puzzle getPuzzle() {
        return puzzle;
    }

    public void setPuzzle(Puzzle puzzle) {
        Puzzle oldPuzzle = this.puzzle;
        this.puzzle = puzzle;
        changeSupport.firePropertyChange("puzzle", oldPuzzle, puzzle);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (questionId != null ? questionId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Question)) {
            return false;
        }
        Question other = (Question) object;
        if ((this.questionId == null && other.questionId != null) || (this.questionId != null && !this.questionId.equals(other.questionId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cw.entity.Question[questionId=" + questionId + "]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

}
